<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //全局作用域中的this指向
        // console.log(this); //window

        //一般函数（非箭头函数）中的this指向问题
        //  'use strict';

        function add() {
            console.log(this);

            //严格模式下this指向undefined
            //undefined ->window(非严格模式下转化为window)
        }

        add();


        //构造函数中的this指向
        function Person(username, password) {
            this.username = username;
            this.password = password;
            console.log(this); //构造函数中的this指向构造函数实例化后生成的对象
        }

        var p = new Person('Cai', 12);
    </script>
</body>

</html>